package com.cqupt.medical.entity.view;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * <p>@author Jay</p>
 * <p>@date 2020/7/26 14:21</p>
 * <p>@Description:</p>
 */
@Getter
@Setter
@ApiModel
@Accessors(chain = true)
public class RespBody<T> implements Serializable {

    private static final RespBody<?> EMPTY_BODY=new RespBody<>().setCode(1);

    //私有化构造器
    private RespBody(){}
    //返回码
    //失败返回2，成功返回1
    @ApiModelProperty("找个码和http状态码没有直接关系，：" +
            "1：请求成功，" +
            "2：请求失败（输入的参数错误，有返回体里有message）")
    private int code;


    @ApiModelProperty("消息")
    private String Message;


    @ApiModelProperty("数据主体")
    private T data;

    //成功无参
    public static RespBody<?> emptyBody(){return EMPTY_BODY;}

    //成功有参
    public static<T> RespBody<T> success(T data){return new RespBody<T>().setCode(1).setData(data);}

    //失败有参
    public static<T> RespBody<T> error(T data){return new RespBody<T>().setCode(2).setData(data) ;}



}
